<template>
  <el-table
      :data="tableData.filter(data => !search || data.name.toLowerCase().includes(search.toLowerCase()))"
      stripe
      style="width: 100%">
    <el-table-column
        label="文件日期"
        prop="ddate">
    </el-table-column>
    <el-table-column
        label="文件名"
        width="280">
      <template slot-scope="scope">
        <el-popover trigger="hover" placement="top">
          <p>文件名: {{ scope.row.dname }}</p>
          <p>文件大小: {{ scope.row.dsize }}(B)</p>
          <div slot="reference" class="name-wrapper">
            <el-button size="medium" style="border: none" @click="dirshow(scope.row.dname)">  <i class="el-icon-picture-outline">{{scope.row.dname}}</i></el-button>
          </div>
        </el-popover>
      </template>
    </el-table-column>
    <el-table-column
        label="文件大小"
        prop="dsize">
    </el-table-column>
    <el-table-column
        label="共享者"
        prop="username">
    </el-table-column>
    <el-table-column
        align="right">
      <template slot="header" slot-scope="scope">
        <el-input
            v-model="search"
            size="mini"
            placeholder="输入关键字搜索"/>
      </template>
      <template slot-scope="scope">
        <el-button
            size="mini"
            @click="dirshow(scope.row.dname)">在线预览</el-button>
        <el-button
            size="mini"
            type="primary"
            @click="dirdown(scope.row.dname,scope.row.username)"><li class="el-icon-download">下载</li></el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
export default {
  inject:　['reload','downloadFiles','dirdown','dirshow'],
  created() {
    var th=this
    axios({
      url:"http://82.156.197.128:8085/dir/findAllShare",
      method:"POST",
    }).then((resp)=>{
      console.log(resp.data);
    th.tableData=resp.data;
    })
  },
  data() {
    return {
      tableData: [{
        ddate: '',
        dname: '',
        dsize: '',
        id:''
      }],
      search: ''
    }
  },
  methods: {
    // dirdown(dname,username){
    //   var th=this;
    //   axios({
    //     url:"http://localhost:8085/user/downDir",
    //     method:"POST",
    //     params:{
    //       "dirname":dname,
    //       "username":username
    //     },
    //     responseType:"blob"
    //   }).then((resp)=>{
    //     th.downloadFiles(resp.data,dname)
    //   })
    //
    // },
    handleEdit(index, row) {
      console.log(index, row);
    },
    handleDelete(index, row) {
      console.log(index, row);
    }
  },
}
</script>